package com.jie.files.service.impl;

import com.jie.files.dao.FilesDao;
import com.jie.files.entity.Files;
import com.jie.files.service.FilesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author Jeson
 * @description
 * @create 2021/10/5
 * @since 1.0.0
 */
@Service
public class FilesServiceImpl implements FilesService {

    @Autowired
    private FilesDao filesDao;

    @Override
    public List<Files> findFilesByUserId(Integer id) {

        return filesDao.findFilesByUserId(id);
    }

    @Override
    public void upload(Files files) {
        String isImg = files.getType().startsWith("image")?"是":"否";
        files.setIsImg(isImg);
        files.setDowncounts(0);
        files.setUploadTime(new Date());
        filesDao.upload(files);
    }

    @Override
    public Files findFileById(Integer id) {
        return filesDao.findFileById(id);
    }

    @Override
    public void addCount(Files file) {
        file.setDowncounts(file.getDowncounts()+1);
        filesDao.addCount(file);
    }

    @Override
    public void deleteById(Integer id) {
        filesDao.deleteById(id);
    }
}